import storageSession from "redux-persist/lib/storage/session";
import {persistReducer} from "redux-persist";
import {SAVE_IS_CURRENT_DATA, SAVE_MULTI_ANALYSIS_INDEX, SAVE_MULTI_DATA,SAVE_IS_RUN_TO_ANALYSIS} from "./constants";

const persistConfig = {
  key: "user",
  storage: storageSession,
  whitelist: ["multiData"] //  白名单:runStart会存入缓存，其他不会存
};

const defaultState = {
  multiData: [],
  isCurrentData: true,
  multiAnalysisIndex: 0,
  isRunToAnalysis:false
};

function reducer(state = defaultState, action) {
  switch (action.type) {
    case SAVE_MULTI_DATA :
      return {...state, multiData: action.multiData};
    case SAVE_IS_CURRENT_DATA :
      return {...state, isCurrentData: action.isCurrentData};
    case SAVE_MULTI_ANALYSIS_INDEX :
      return {...state, multiAnalysisIndex: action.multiAnalysisIndex};
      case SAVE_IS_RUN_TO_ANALYSIS :
      return {...state, isRunToAnalysis: action.isRunToAnalysis};
    default:
      return state;
  }
}

export default persistReducer(persistConfig, reducer);
